<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ include file="../../include/taglibs.jsp" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <title>虚拟数据列表</title>
    <style type="text/css">
        html, body {
            margin: 0;
            padding: 0;
            border: 0;
            width: 100%;
            height: 100%;
            overflow: hidden;
        }

    </style>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8"/>
    <link href="/css/demo.css" rel="stylesheet" type="text/css"/>
    <script src="/scripts/boot.js" type="text/javascript"></script>
</head>
<body>

<div style="padding-bottom:5px;padding-left: 0px;">

    <div id="form1">
        <table border="0" cellpadding="1" cellspacing="2">
            <tr>
            <td>状态：</td>
					<td>
					<input name="status" class="mini-combobox" style="width:150px;" onvaluechanged="search()"
                                   textField="text" valueField="code" emptyText="请选择..."
                                   url="/gamblingPeriod/getPeriodStatus.action" showNullItem="true"
                                   nullItemText="请选择..."/>
                                   </td>
                <td>
                   	 期号：
                </td>
                <td>
                    <input name="period" id="period" emptyText="请输入期号" class="mini-textbox"/>
                </td>
                <td colspan="2" align="center"><a class="mini-button" iconCls="icon-search" onClick="search()">搜索</a>&nbsp;<a
                        class="mini-button" iconCls="icon-reload" onClick="clean()">重置</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div style="width:99%;">
    <div class="mini-toolbar" style="border-bottom:0;padding:0px;">
        <table style="width:100%;">
            <tr>
                <td style="width:100%;">
                    <a class="mini-button" iconCls="icon-add" onclick="add()">增加</a>
                    <a class="mini-button" iconCls="icon-upload" onclick="batchImportVirtualData()">批量导入虚拟数据</a>
                </td>
            </tr>
        </table>
    </div>
</div>
<div id="datagrid1" class="mini-datagrid" style="width:99%;height:85%;"
     url="/virtualData/queryVirtualData.action" idField="id" allowResize="true" allowCellWrap="true"
     >
    <div property="columns">
        <div type="indexcolumn"></div>
        <div field="id" width="100" headerAlign="center" align="center">ID</div>
        <div field="periodId" width="100" headerAlign="center" align="center">期号</div>
        <div field="product.nameEn" width="120" headerAlign="center" align="center">商品名称</div>
        <div field="virtualKey" width="200" headerAlign="center" align="center">序列号</div>
        <div field="secret" width="200" headerAlign="center" align="center">秘钥</div>
        <div field="virtualStatusEnum.text" width="100" headerAlign="center" align="center">状态</div>
		<div name="action" width="100" headerAlign="center" align="center"
				renderer="onActionRenderer" cellStyle="padding:0;">操作</div>
    </div>
</div>

<script type="text/javascript">

    mini.parse();
    var grid = mini.get("datagrid1");
    var form = new mini.Form("#form1"); //获取表单对象
    grid.load();
    //查询
    function search() {
        var data = form.getData();      //获取表单多个控件的数据
        data.productId = globalProductId;
        var json = mini.encode(data);   //序列化成JSON
        grid.load({json: json});
    }

    function clean() {
        form.reset();
    }
	function onActionRenderer(e) {
		var record = e.record;
		var uid = record.id;
		var rowIndex = e.rowIndex;
		var s = ' <a class="Edit_Button" href="javascript:edit(\'' + uid
				+ '\')" >Edit</a>'
				+ ' <a class="Edit_Button" href="javascript:remove(\''
				+ uid + '\')">Delete</a>';
		return s;
	}
    function add() {
        mini.open({
            url: "<c:url value='/virtualData/addvirtualDataPage.action'/>",
            title: "虚拟数据添加", width: 666, height: 399,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = {action: "new"};
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                if (action == "save") {
                    grid.reload();
                    mini.showTips({
                        content: "<b>成功</b> <br/>虚拟数据添加成功",
                        state: "success",
                        x: "center",
                        y: "center",
                        timeout: 3000
                    });
                }
            }
        });
    }
    function edit(id) {
        var row = grid.getSelected();
        if (row) {
            mini.open({
                url: "<c:url value='/virtualData/addvirtualDataPage.action'/>",
                title: "虚拟数据修改", width: 666, height: 399,
                onload: function () {
                    var iframe = this.getIFrameEl();
                    var data = {action: "edit", virtualId: row.id};
                    iframe.contentWindow.SetData(data);
                },
                ondestroy: function (action) {
                    if (action == "save") {
                        grid.reload();
                        mini.showTips({
                            content: "<b>成功</b> <br/>虚拟数据修改成功",
                            state: "success",
                            x: "center",
                            y: "center",
                            timeout: 3000
                        });
                    }
                }
            });
        }
    }
	function remove() {
		var row = grid.getSelected();
		if (confirm("确定删除选中记录？")) {
			grid.loading("操作中，请稍后......");
			$.ajax({
				url : "/virtualData/deleteVirtualData.action",
				data : {
					id : row.id
				},
				success : function() {
					grid.reload();
					mini.showTips({
						content : "<b>成功</b> <br/>虚拟数据删除成功",
						state : "success",
						x : "center",
						y : "center",
						timeout : 3000
					});
				},
				error : function(jqXHR, textStatus, errorThrown) {
					grid.reload();
					mini.showMessageBox({
						showModal : false,
						width : 250,
						title : "提示",
						iconCls : "mini-messagebox-warning",
						message : jqXHR.responseText,
						timeout : 3000,
						x : "right",
						y : "bottom"
					});
				}
			});
		}
	}
	function batchImportVirtualData(){
		mini.open({
        	url: "/virtualData/importVirtualDataPage.action",
        	title: "批量导入虚拟数据", width: 500, height: 200,
            ondestroy: function (action) {
            }
    	});	
	}
</script>
</body>
</html>
